package com.chinairi.mall.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.chinairi.common.utils.ResponseUtil;
import com.chinairi.mall.controller.viewobject.GoodsClassCodeVO;
import com.chinairi.mall.controller.viewobject.GoodsInfoVO;
import com.chinairi.mall.model.GoodsClassCode;
import com.chinairi.mall.service.IGoodsClassCodeService;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.chinairi.common.controller.BaseController;

import java.io.IOException;
import java.util.List;

/**
 * <p>
 * 商品分类编码表 前端控制器
 * </p>
 *
 * @author gsl
 * @since 2020-08-17
 */
@RestController
@RequestMapping("/goods-class-code")
public class GoodsClassCodeController extends BaseController {

    @Autowired
    private IGoodsClassCodeService iGoodsClassCodeService;

    /**
     * 获取所有商品分类，树形结构（新方法）
     * @throws Exception
     */
    @GetMapping("/getGoodsClass")
    public void getGoodsClass()throws Exception {
        List<GoodsClassCodeVO> goodsClassCodeVOList = iGoodsClassCodeService.getGoodsClass();
        ResponseUtil.showMessage("success", "获取商品大类", goodsClassCodeVOList);
    }

    /**
     * 获取商品大类
     *
     * @throws Exception
     */
    @GetMapping("/getBig")
    public void getBigClass() throws Exception {
        List<GoodsClassCodeVO> goodsClassCodeVOList = iGoodsClassCodeService.getBigClass();
        ResponseUtil.showMessage("success", "获取商品大类", goodsClassCodeVOList);
    }

    /**
     * 查询某一分类下的子类
     *
     * @param goodsClassDbid
     * @throws Exception
     */
    @GetMapping("/getSub")
    public void getSubClass(String goodsClassDbid) throws Exception {
        List<GoodsClassCodeVO> goodsClassCodeVOList = iGoodsClassCodeService.getSubClass(goodsClassDbid);
        ResponseUtil.showMessage("success", "某一分类下的子类", goodsClassCodeVOList);
    }

    /**
     *
     * @throws IOException
     */
    @GetMapping("/getAllClass")
    public void getAllClass() throws IOException {
        List<GoodsClassCodeVO> goodsClassCodeVOList = iGoodsClassCodeService.getAllClass();
        ResponseUtil.showMessage("success", "所有分类", goodsClassCodeVOList);
    }


    /**
     * 获取小类下的商品
     *
     * @param goodsClassCodeVO
     * @throws IOException
     */
    @GetMapping("/getGoods")
    public void getGoods(@RequestBody GoodsClassCodeVO goodsClassCodeVO) throws IOException {
        String goodsClassDbid = goodsClassCodeVO.getGoodsClassDbid();
        List<GoodsInfoVO> goodsInfoVOList = iGoodsClassCodeService.getGoodsByClassCode(goodsClassDbid);
        ResponseUtil.showMessage("success", "某一小类下的全部商品", goodsInfoVOList);

    }
}
